package com.wisdudu.blank.support.widget.loading;

import android.view.View;

import com.kelin.mvvmlight.command.ReplyCommand;

/**
 * Created by qyf on 2016/9/29.
 */

public final class ViewBindingAdapter {
    @android.databinding.BindingAdapter({"pageStatus"})
    public static void changeLoadingStatus(LoadingFrameLayout loadFL, @PGSTATUS int pageStatus) {
        switch (pageStatus) {
            case LoadingConstant.LOADING:
                loadFL.showLoadingView();
                break;
            case LoadingConstant.CONTENT:
                loadFL.showContentView();
                break;
            case LoadingConstant.EMPTY:
                loadFL.showEmptyView();
                break;
            case LoadingConstant.ERROR:
                loadFL.showErrorView();
                break;
            default:
                loadFL.showLoadingView();
                break;
        }
    }

    @android.databinding.BindingAdapter({"errorText"})
    public static void setErrorText(LoadingFrameLayout loadFL, String errorText) {
        loadFL.setErrorText(errorText);
    }


    @android.databinding.BindingAdapter({"emptyRetryText"})
    public static void setEmptyRetryText(LoadingFrameLayout loadFL, String errorText) {
        loadFL.setEmptyRetryText(errorText);
    }

    @android.databinding.BindingAdapter(value = {"onErrorRetryCommand", "onEmptyRetryCommand"})
    public static void retryCommand(LoadingFrameLayout loadFL, final ReplyCommand onErrorRetryClick
            , final ReplyCommand onEmptyRetryClick) {
        loadFL.setOnLoadClickListener(new LoadingFrameLayout.OnLoadRetryClickListener() {
            @Override
            public void onErrorRetryClick(View view) {
                if (onErrorRetryClick != null) {
                    onErrorRetryClick.execute();
                }
            }

            @Override
            public void onEmptyRetryClick(View view) {
                if (onEmptyRetryClick != null) {
                    onEmptyRetryClick.execute();
                }
            }
        });
    }
}
